from rest_framework import mixins, viewsets
from rest_framework.mixins import CreateModelMixin

from apps.book.models.AuthorInfo import AuthorInfo
from apps.book.models.BookInfo import BookInfo
from apps.book.models.CategoryInfo import CategoryInfo
from apps.book.models.PubHouse import PubHouse
from apps.book.serializer import (
    BookInfoReadSerializer,
    BookInfoCreateSerializer,
    AuthorInfoReadSerializer,
    AuthorInfoCreateSerializer,
    CategoryInfoReadSerializer, PubHouseInfoReadSerializer
)
from rest_framework import permissions


# 书籍crud
class BookInfoView(viewsets.ModelViewSet):
    queryset = BookInfo.objects.all().order_by('id')
    serializer_class = BookInfoReadSerializer
    create_serializer_class = BookInfoCreateSerializer
    update_serializer_class = BookInfoCreateSerializer
    permissions_class = [permissions.IsAuthenticated]


# 作者crud
class AuthorInfoView(viewsets.ModelViewSet):
    queryset = AuthorInfo.objects.all().order_by('id')
    serializer_class = AuthorInfoReadSerializer
    create_serializer_class = AuthorInfoCreateSerializer
    update_serializer_class = AuthorInfoCreateSerializer
    permissions_class = [permissions.IsAuthenticated]


# 书籍种类crud
class CategoryInfoView(viewsets.ModelViewSet):
    queryset = CategoryInfo.objects.all().order_by('id')
    serializer_class = CategoryInfoReadSerializer
    permissions_class = [permissions.IsAuthenticated]


# 出版社crud
class PubHouseInfoView(viewsets.ModelViewSet):
    queryset = PubHouse.objects.all().order_by('id')
    serializer_class = PubHouseInfoReadSerializer
    create_serializer_class = PubHouseInfoReadSerializer
    update_serializer_class = PubHouseInfoReadSerializer
    permissions_class = [permissions.IsAuthenticated]
